package jaux.tank.api.controller.system;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import jaux.tank.api.controller.BaseController;
import jaux.tank.bean.constant.factory.PageFactory;
import jaux.tank.bean.entity.system.LoginLog;
import jaux.tank.bean.vo.front.Ret;
import jaux.tank.bean.vo.front.Rets;
import jaux.tank.dao.system.LoginLogRepository;
import jaux.tank.service.system.LoginLogService;
import jaux.tank.utils.BeanUtil;
import jaux.tank.utils.factory.Page;
import jaux.tank.warpper.LogWarpper;

/**
 * LoginLogController
 *
 * @author zt
 * @version 2018/10/5 0005
 */
@RestController("loginLogApiController")
@RequestMapping("/api/loginLog")
public class LoginLogController extends BaseController {

    @Resource
    private LoginLogRepository loginLogRepository;
    @Autowired
    private LoginLogService loginlogService;
    
    @ApiOperation(value = "查询登录日志")
    @GetMapping("/list")
    public Ret<Page<LoginLog>> list(@RequestParam(required = false) String beginTime
    		, @RequestParam(required = false) String endTime
    		, @RequestParam(required = false) String logname
    		, @RequestParam(required = false) String userId) {
        Page<LoginLog> page =  loginlogService.getLoginLogs(new PageFactory<LoginLog>().defaultPage(), beginTime, endTime, userId, logname);
        return Rets.success(page);

    }


    /**
     * 清空日志
     */
    @ApiOperation(value = "清除登录日志")
    @DeleteMapping
    public Ret<Object> delLog() {
        loginLogRepository.clear();
        return Rets.success();
    }
}
